﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.DTO.Carrier;
using XuanKeZz.Application.HTTP;
using static WMSUIMVC.Controllers.FinanceController;

namespace WMSUIMVC.Controllers
{
    /// <summary>
    /// 模板
    /// </summary>
    public class CarrierController : Controller
    {
        private readonly IConfiguration _configuration;

        public CarrierController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        
        
        public IActionResult GetCarrier()
        {
            return View();
        }
        /// <summary>
        /// 显示承运商管理
        /// 调用网关获取数据
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetCarrierModel(SelectCarrierDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] +"sbd/api/CarriersModels/SelectCarrierModel?CarriersCode=" +dto.CarriersCode + "&CarriersName="+dto.CarriersName + "&pageindex="+dto.PageIndex+"&pagesize="+dto.PageSize;
            string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        
        
        }
        /// <summary>
        /// 添加承运商
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public async Task<IActionResult> AddCarrier(AddCarrierDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+"sbx/api/Carrier/AddCarriers";

            string list = JsonConvert.SerializeObject(dto);

            string GetFinance = await client.PostAsync(url, list);
            return Json(GetFinance);
        }
        /// <summary>
        /// 反填承运商
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public async Task<IActionResult> FanCarrier(FanCarrierDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "sbd/api/CarriersModels/FanCarrierModel?id=" + dto.id;
             string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        }

        /// <summary>
        /// 修改承运商
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public async Task<IActionResult> UpdCarrier(UpdCarrierDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "sbx/api/Carrier/UpdCarriers";

            string list = JsonConvert.SerializeObject(dto);

            string GetFinance = await client.PutAsync(url, list);
            return Json(GetFinance);
        }



        /// <summary>
        /// 删除承运商
        /// </summary>
        /// <param name="Token"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelCarrier(DelCarrierDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "sbx/api/Carrier/DelCarriers";
            string list = JsonConvert.SerializeObject(dto);
            string GetFinance = await client.PostAsync(url, list);
            return Json(GetFinance);
        }









    }
}
